﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:Expander;assembly=Expander"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"    
    >

    <Style TargetType="local:ExpanderControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:ExpanderControl">
                    <Grid Background="{TemplateBinding Background}">
                        <Grid.Resources>
                            <Style x:Key="ArrowCheckBoxStyle" TargetType="CheckBox">
                                <Setter Property="IsEnabled" Value="true"/>
                                <Setter Property="IsTabStop" Value="true"/>
                                <Setter Property="Background" Value="#FF003255"/>
                                <Setter Property="Foreground" Value="#FF313131"/>
                                <Setter Property="Margin" Value="0"/>
                                <Setter Property="HorizontalContentAlignment" Value="Left"/>
                                <Setter Property="VerticalContentAlignment" Value="Center"/>
                                <Setter Property="Cursor" Value="Arrow"/>                                
                                <Setter Property="FontSize" Value="11"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="CheckBox">
                                            <Grid Cursor="Arrow" Background="{TemplateBinding Background}">
                                                <Grid.Resources>
                                                    <SolidColorBrush x:Key="Background" Color="#FF003255"/>
                                                    <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF"/>
                                                    <LinearGradientBrush x:Key="BoxStrokeBrush" EndPoint="0.5,1" StartPoint="0.5,0">
                                                        <GradientStop Color="#FF000000" Offset="0"/>
                                                        <GradientStop Color="#FF000000" Offset="1"/>
                                                        <GradientStop Color="#FF000000" Offset="0.325"/>
                                                        <GradientStop Color="#FF000000" Offset="0.325"/>
                                                    </LinearGradientBrush>
                                                    <LinearGradientBrush x:Key="FocusedStrokeBrush" EndPoint="0.5,1" StartPoint="0.5,0">
                                                        <GradientStop Color="#B2FFFFFF" Offset="0"/>
                                                        <GradientStop Color="#51FFFFFF" Offset="1"/>
                                                        <GradientStop Color="#66FFFFFF" Offset="0.325"/>
                                                        <GradientStop Color="#1EFFFFFF" Offset="0.325"/>
                                                    </LinearGradientBrush>
                                                    <Color x:Key="BorderColor">#FF000000</Color>
                                                    <Color x:Key="IconColor">#FF313131</Color>
                                                    <Color x:Key="PressedIconColor">#FF000000</Color>
                                                    <Color x:Key="MiddleBoxStrokeBrush">#FFADADAD</Color>
                                                    <Color x:Key="MiddleBoxStrokeBrushOver">#FF656565</Color>
                                                    <Color x:Key="LinearBevelLightStartColor">#FFFFFFFF</Color>
                                                    <Color x:Key="LinearBevelLightEndColor">#FFFFFFFF</Color>
                                                    <Color x:Key="LinearBevelDarkStartColor">#FFFFFFFF</Color>
                                                    <Color x:Key="LinearBevelDarkEndColor">#FFFFFFFF</Color>
                                                    <Color x:Key="LinearBevelLightStartColor2">#FCFFFFFF</Color>
                                                    <Color x:Key="LinearBevelLightEndColor2">#F4FFFFFF</Color>
                                                    <Color x:Key="LinearBevelDarkStartColor2">#E0FFFFFF</Color>
                                                    <Color x:Key="LinearBevelDarkEndColor2">#19FFFFFF</Color>
                                                    <Color x:Key="LinearBevelLightEndColor3">#FCFFFFFF</Color>
                                                    <Color x:Key="LinearBevelDarkStartColor3">#FCFFFFFF</Color>
                                                    <Color x:Key="LinearBevelDarkEndColor3">#FCFFFFFF</Color>
                                                    <Color x:Key="LinearBevelIndeterminateStartColor2">#BFFFFFFF</Color>
                                                    <Color x:Key="LinearBevelIndeterminateEndColor2">#E0FFFFFF</Color>
                                                    <Color x:Key="FocusColor">#FF333333</Color>
                                                </Grid.Resources>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <vsm:VisualStateManager.VisualStateGroups>
                                                    <vsm:VisualStateGroup x:Name="CommonStates">
                                                        <vsm:VisualStateGroup.Transitions>
                                                            <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver"/>
                                                            <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="Pressed"/>
                                                        </vsm:VisualStateGroup.Transitions>
                                                        <vsm:VisualState x:Name="Normal"/>
                                                        <vsm:VisualState x:Name="MouseOver">
                                                            <Storyboard/>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="Pressed">
                                                            <Storyboard/>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="Disabled">
                                                            <Storyboard>
                                                                <DoubleAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="DisabledBox" Storyboard.TargetProperty="Opacity">
                                                                    <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                                                                </DoubleAnimationUsingKeyFrames>
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                    </vsm:VisualStateGroup>
                                                    <vsm:VisualStateGroup x:Name="CheckStates">
                                                        <vsm:VisualStateGroup.Transitions>
                                                            <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="Indeterminate"/>
                                                        </vsm:VisualStateGroup.Transitions>
                                                        <vsm:VisualState x:Name="Checked">
                                                            <Storyboard>
                                                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="UncheckedIcon" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                                        <DiscreteObjectKeyFrame.Value>
                                                                            <Visibility>Collapsed</Visibility>
                                                                        </DiscreteObjectKeyFrame.Value>
                                                                    </DiscreteObjectKeyFrame>
                                                                </ObjectAnimationUsingKeyFrames>
                                                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="CheckIcon" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                                        <DiscreteObjectKeyFrame.Value>
                                                                            <Visibility>Visible</Visibility>
                                                                        </DiscreteObjectKeyFrame.Value>
                                                                    </DiscreteObjectKeyFrame>
                                                                </ObjectAnimationUsingKeyFrames>
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="Unchecked">
                                                            <Storyboard>
                                                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="CheckIcon" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                                        <DiscreteObjectKeyFrame.Value>
                                                                            <Visibility>Collapsed</Visibility>
                                                                        </DiscreteObjectKeyFrame.Value>
                                                                    </DiscreteObjectKeyFrame>
                                                                </ObjectAnimationUsingKeyFrames>
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="Indeterminate">
                                                            <Storyboard/>
                                                        </vsm:VisualState>
                                                    </vsm:VisualStateGroup>
                                                    <vsm:VisualStateGroup x:Name="FocusStates">
                                                        <vsm:VisualState x:Name="Unfocused">
                                                            <Storyboard>
                                                                <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ContentFocusVisual" Storyboard.TargetProperty="Visibility">
                                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                                        <DiscreteObjectKeyFrame.Value>
                                                                            <Visibility>Collapsed</Visibility>
                                                                        </DiscreteObjectKeyFrame.Value>
                                                                    </DiscreteObjectKeyFrame>
                                                                </ObjectAnimationUsingKeyFrames>
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="Focused">
                                                            <Storyboard>
                                                                <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ContentFocusVisual" Storyboard.TargetProperty="Visibility">
                                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                                        <DiscreteObjectKeyFrame.Value>
                                                                            <Visibility>Collapsed</Visibility>
                                                                        </DiscreteObjectKeyFrame.Value>
                                                                    </DiscreteObjectKeyFrame>
                                                                </ObjectAnimationUsingKeyFrames>
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="ContentFocused">
                                                            <Storyboard>
                                                                <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ContentFocusVisual" Storyboard.TargetProperty="Visibility">
                                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                                        <DiscreteObjectKeyFrame.Value>
                                                                            <Visibility>Visible</Visibility>
                                                                        </DiscreteObjectKeyFrame.Value>
                                                                    </DiscreteObjectKeyFrame>
                                                                </ObjectAnimationUsingKeyFrames>
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                    </vsm:VisualStateGroup>
                                                </vsm:VisualStateManager.VisualStateGroups>
                                                <Path x:Name="CheckIcon"  Height="16" Width="24" Stretch="Fill" Stroke="#FF000000" Data="M2,2 L9,16 L16,2" StrokeThickness="3" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeDashCap="Flat" StrokeLineJoin="Round" RenderTransformOrigin="0.5,0.5" Visibility="Collapsed">
                                                    <Path.RenderTransform>
                                                        <RotateTransform Angle="180" />
                                                    </Path.RenderTransform>
                                                </Path>
                                                <Path x:Name="UncheckedIcon" Height="16" Width="24" Stretch="Fill" Stroke="#FF000000" Data="M2,2 L9,16 L16,2" StrokeThickness="3" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeDashCap="Flat" StrokeLineJoin="Round"/>
                                                <Rectangle Margin="2" x:Name="ContentFocusVisual" IsHitTestVisible="false" Visibility="Collapsed" Grid.Column="1" StrokeDashArray=".2 2" StrokeDashCap="Round">
                                                    <Rectangle.Stroke>
                                                        <SolidColorBrush Color="{StaticResource FocusColor}"/>
                                                    </Rectangle.Stroke>
                                                </Rectangle>
                                                <ContentPresenter Margin="6,5.5,4,4" x:Name="Content" IsHitTestVisible="true" Grid.Column="1" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
                                                <Rectangle Height="20" x:Name="DisabledBox" VerticalAlignment="Center" Width="24" Opacity="0" Fill="{StaticResource DisabledBrush}" Stroke="{StaticResource DisabledBrush}" StrokeThickness=".75" RadiusX="1" RadiusY="1"/>
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Grid.Resources>
                        
                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="PresentationStates">
                                <vsm:VisualState x:Name="Collapsed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="00:00:00" Storyboard.TargetName="expandArea" Storyboard.TargetProperty="(Border.Visibility)">
                                            <ObjectKeyFrameCollection>
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Collapsed</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectKeyFrameCollection>
                                        </ObjectAnimationUsingKeyFrames>                                        
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="Expanded">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="00:00:00" Storyboard.TargetName="expandArea" Storyboard.TargetProperty="(Border.Visibility)">
                                            <ObjectKeyFrameCollection>
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectKeyFrameCollection>
                                        </ObjectAnimationUsingKeyFrames>                                        
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>

                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <CheckBox x:Name="PART_HeaderToggleButton" Grid.Row="0" Style="{StaticResource ArrowCheckBoxStyle}" Margin="5,3,5,3" Background="Transparent"/>                        
                        <Border x:Name="expandArea" Grid.Row="1" Visibility="Collapsed">
                            <ContentPresenter />
                        </Border>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>